package com.casit.base.util;

import com.casit.base.entity.BaseEntity;
import com.casit.base.enums.ResultEnum;
import com.casit.base.model.ResultModel;
import com.monitorjbl.json.JsonResult;
import com.monitorjbl.json.JsonView;
import com.monitorjbl.json.Match;

/**
 * 返回结果工具类
 */
public class ResultUtil {
    public static ResultModel successJsonView(JsonResult jsonResult, String[] filterResult, Object data) {
        return jsonResult.use(JsonView.with(success(data))
                .onClass(BaseEntity.class, Match.match()
                        .exclude(filterResult)
                )
        ).returnValue();
    }

    public static ResultModel success(Object data) {
        return new ResultModel(ResultEnum.SUCCESS, data);
    }

    public static ResultModel fail(int code, String message) {
        return new ResultModel(code, message);
    }

    public static ResultModel fail(String message) {
        return new ResultModel(ResultEnum.UNKONW_ERROR, message);
    }
}
